package com.example.excelimporter.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Data
@Entity
@Table(name = "template_configs")
@Schema(description = "Configuration for Excel import templates")
public class TemplateConfig {
    @Id
    @Schema(description = "Unique identifier of the template", example = "template-123")
    private String id;

    @Column(nullable = false)
    @Schema(description = "Name of the template", example = "Customer Import Template")
    private String templateName;

    @Column(columnDefinition = "TEXT")
    @Schema(description = "Description of the template's purpose", example = "Template for importing customer data from Excel")
    private String description;

    @Column(nullable = false)
    @Schema(description = "Target database table name", example = "customers")
    private String targetTable;

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "template_id")
    @Schema(description = "List of field configurations for the template")
    private List<FieldConfig> fieldConfigs;

    @Transient
    @Schema(description = "Data class for mapping Excel data", hidden = true)
    private Class<?> dataClass;

    @ElementCollection
    @CollectionTable(name = "template_listeners", joinColumns = @JoinColumn(name = "template_id"))
    private List<ListenerConfig> listeners;
}
